//
//  VCOfMyPublish.m
//  LCOnePsychology
//
//  Created by li cheng on 16/9/23.
//  Copyright © 2016年 li cheng. All rights reserved.
//

#import "VCOfMyPublish.h"
#import "BaseButton.h"
#import "MJMacro.h"
#import "BaseCollectionView.h"
#import "CVCellOfMyPublish.h"
@interface VCOfMyPublish ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UIView *blueView;
@property (nonatomic, strong) BaseCollectionView *collectionViewOfCollect;
@end

@implementation VCOfMyPublish

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"< 返回" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    // 创建上面的 button
    [self createAboveButton];
    // 创建 collectionView
    [self createCollectionView];
}
#pragma mark - 返回的实现方法
- (void)back:(UIBarButtonItem *)barButtonItem{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
#pragma mark - 创建子上面的 label
- (void)createAboveButton{
    // 文章 button
    BaseButton *buttonOfArticle = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfArticle.frame = CGRectMake(0, 0, SCREEN_WIDTH / 4, 44);
    buttonOfArticle.backgroundColor = [UIColor whiteColor];
    [buttonOfArticle setTitle:@"文章" forState:UIControlStateNormal];
    [buttonOfArticle addTarget:self action:@selector(clickArticleButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonOfArticle];
    // 测试 button
    BaseButton *buttonOfTest = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfTest.frame = CGRectMake(SCREEN_WIDTH / 3, 0, SCREEN_WIDTH / 4, 44);
    buttonOfTest.backgroundColor = [UIColor whiteColor];
    [buttonOfTest setTitle:@"提问" forState:UIControlStateNormal];
    [buttonOfTest addTarget:self action:@selector(clickTestButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonOfTest];
    // FM电台 button
    BaseButton *buttonOfFM = [BaseButton buttonWithType:UIButtonTypeSystem];
    buttonOfFM.frame = CGRectMake(SCREEN_WIDTH / 3 * 2, 0, SCREEN_WIDTH / 4, 44);
    buttonOfFM.backgroundColor = [UIColor whiteColor];
    [buttonOfFM setTitle:@"回答" forState:UIControlStateNormal];
    [buttonOfFM addTarget:self action:@selector(clickFMButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:buttonOfFM];
    // 下面的蓝色的条
    self.blueView = [[UIView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH / 8 - 40, 42, 80, 2)];
    self.blueView.backgroundColor = [UIColor blueColor];
    [self.view addSubview:_blueView];
}
#pragma mark - 文章的 button 的实现方法
- (void)clickArticleButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40, 42, 80, 2);
    self.collectionViewOfCollect.contentOffset = CGPointMake(0, 0);
}
#pragma mark - 测试的 button 的实现方法
- (void)clickTestButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40 + SCREEN_WIDTH / 3, 42, 80, 2);
    self.collectionViewOfCollect.contentOffset = CGPointMake(SCREEN_WIDTH, 0);
}
#pragma mark - 电台的 button 的实现方法
- (void)clickFMButton:(UIButton *)button{
    self.blueView.frame = CGRectMake(SCREEN_WIDTH / 8 - 40 + SCREEN_WIDTH / 3 * 2, 42, 80, 2);
    self.collectionViewOfCollect.contentOffset = CGPointMake(SCREEN_WIDTH * 2, 0);
}
#pragma mark - 创建 collectionView
- (void)createCollectionView{
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.itemSize = CGSizeMake(SCREEN_WIDTH, SCREEN_HEIGHT - 44 - 64);
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    self.collectionViewOfCollect = [[BaseCollectionView alloc] initWithFrame:CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_HEIGHT - 44 - 64) collectionViewLayout:layout];
    self.collectionViewOfCollect.pagingEnabled = YES;
    [self.view addSubview:_collectionViewOfCollect];
    self.collectionViewOfCollect.delegate = self;
    self.collectionViewOfCollect.dataSource = self;
    [self.collectionViewOfCollect registerClass:[CVCellOfMyPublish class] forCellWithReuseIdentifier:@"CVCellOfMyPublish"];
}
#pragma mark - CollectionView 的代理方法 item 的数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}
#pragma mark - CollectView 的代理方法 cell 的赋值
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    CVCellOfMyPublish *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CVCellOfMyPublish" forIndexPath:indexPath];
    cell.numberOfRow = indexPath.row;
    cell.backgroundColor = [UIColor colorWithRed:arc4random() % 256 / 255.0f green:arc4random() % 256 / 255.0f blue:arc4random() % 256 / 255.0f alpha:1];
    return cell;
}
#pragma mark - scrollView 的滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.contentOffset.x == 0) {
        [self clickArticleButton:nil];
    }
    if (scrollView.contentOffset.x == SCREEN_WIDTH) {
        [self clickTestButton:nil];
    }
    if (scrollView.contentOffset.x == SCREEN_WIDTH * 2) {
        [self clickFMButton:nil];
    }
}
#pragma mark - 其他, 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
